package ms.jasim.model.presentation;

import ms.jasim.model.JasimModel;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Composite;


public class PddlViewer extends TextViewer {
	
	public PddlViewer(Composite composite, int style) {
		super(composite, SWT.V_SCROLL | SWT.H_SCROLL);
		setEditable(false);
		Font oldFont = getTextWidget().getFont();
		getTextWidget().setFont(new Font(oldFont.getDevice(), "Courier New",  10, SWT.NORMAL));
	}
	
	@Override
	public void setInput(Object input) {
		if (input instanceof XMIResource) {
			EList<EObject> contents = ((XMIResource) input).getContents();
			if (contents.size() > 0 && contents.get(0) instanceof JasimModel) {
				JasimModel model = (JasimModel) contents.get(0);
				super.setInput(new Document(model.generatePddlProblem().toString()));
			}
		}
		else super.setInput(input);
	}
}
